<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SOP管理</title>
<!--<link href="/css/formcheck.css" rel="stylesheet" >-->
<link rel="import" href="../includes/baseInclude.html">
<style type="text/css">
.ui-jqgrid tr.jqgrow td { white-space: normal !important; height:auto; }
/*jqgrid首行背景色*/
.ui-th-column{
	background-color:#ffffff !important;
	text-align: center !important;
	/*border: none !important;*/
}
/*表格去除竖线*/
table.table-bordered td {
	border: none !important;
	text-align: center !important;
}
/*checkbox前面的*/
#sopTableList_rn{
	width: 29px !important;
}
   .ui-jqgrid-bdiv{
	   border: none !important;
   }
   .ui-pg-input{
	   border: none !important;
   }
	.ui-jqgrid-hbox{
		border: none !important;
	}
	.btn{
		outline: none;
		background-image: url(../images/btn.png);
		background-repeat:no-repeat;
		margin-left: 15px;
		width: 85px;
		height: 55px;
		background-color: #ffffff;
		border: none;
		text-align: center;
	}
	.btn:hover{
		outline: none;
		 background-image: url(../images/btn_mouseOver.png);
		 margin-left: 15px;
		 color:#ffffff;
		 width: 85px;
		 height: 55px;
		 background-color: #ffffff;
		 border: none;
		 text-align: center;
	 }
	.btn:active{
		outline: none;
		background-image: url(../images/btn_mouseOver.png);
		margin-left: 15px;
		color:#ffffff;
		width: 85px;
		height: 55px;
		background-color: #ffffff;
		border: none;
		text-align: center;
	}
	.btn:focus{
		outline: none;
		background-image: url(../images/btn_mouseOver.png);
		margin-left: 15px;
		color:#ffffff;
		width: 85px;
		height: 55px;
		background-color: #ffffff;
		border: none;
		text-align: center;
		}
     button::-moz-focus-inner {
			border: 0;
		}
</style>
</head>
<body ng-app="sopApp" ng-controller="sopCtrl">
	<div id="manage-area-title">
	<div class="pd-20">
		<div style="margin-bottom: 10px;" >
			<button class="btn" ng-click="datadel()">批量删除</button>
			<button class="btn" ng-click="layer_show('添加SOP','sopManagement-add.html','800px','350px')">新增</button>
			<button class="btn">停止</button>
		</div>
    
		<div style="clear: both;"></div>
		<div  style="width: 100%;" class="jqGrid_wrapper">
			<table id="sopTableList" style="border: none;"></table>
			<div id="sopTableListPager"></div>
		</div>
	</div>	
	</div>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
	<!--<script type="text/javascript" src="/pc/base/js/laydate/laydate.js"></script>-->
    <script type="text/javascript" src="../js/base/jqGrid.js"></script>
    <script type="text/javascript" src="../js/libs/gridUtil.js"></script>
	<!--<script type="text/javascript" src="../js/instruct.js"></script>-->
	<script>
		//angularjs post 提交时HTTP头设置
		var transform = function (data) {
			return $.param(data);
		}, postCfg = {
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
			},
			transformRequest: transform
		};
		var app = angular.module('sopApp',[]);
		    app.controller('sopCtrl',function($scope,$http){
				/*刷新*/
				$scope.reload = function(){
					$scope.projectName = "";
					$scope.search();
				}
//				/*搜索合同*/
//				$scope.projectName = "";
//				$scope.search = function(name){
//					var data = {'SalesBidding.name':name};
//					$("#sopTableList").setGridParam({
//						url:"/salesBidding/findBidding",
//						datatype: "json",
//						page:1
//					});
//					$("#sopTableList").setPostData(data);
//					$("#sopTableList").trigger("reloadGrid");
//				};

		    	//弹出框layerShow
		    	$scope.layer_show = function(title,url,width,height){
                   layer.open({
	                   	type:2,
	                   	title:title,
	                   	content:url,
	                   	shadeClose:false,
	                    shade:0.2,
	                    maxmin: true,
	                    closeBtn:1,
	                    area: [width, height],
	                    end:function(){
	                    	refresh();//关闭layer,刷新方法
	                    }
                   })
		    	};

				/*选中删除 checkBox*/
				function getSelectedIds(){
					$scope.selectedIds = $("#sopTableList").jqGrid("getGridParam", "selarrrow");
					return $scope.selectedIds;
				};
				/*批量删除*/
				$scope.datadel = function() {
					getSelectedIds();
					if($scope.selectedIds.length==0){//没有选择一个的时候提示
						layer.msg('请至少选中一条数据再操作！',{icon:2,time:1000});
						return;
					}else{
						layer.confirm('确定要删除么，操作需谨慎？',function(){
							var dataManyDele={
								'biddingIds':$scope.selectedIds
							};
							$http.post('/salesBidding/deleteBiddingBatch',dataManyDele,postCfg)
									.success(function(resp){
										if(validateSuccessData(resp)){
											layer.msg('删除成功',{icon:1,time:500});
											window.refresh();
										}else{
											layer.msg(resp.errorMessage,{icon:2,time:1000});
										}
									});
						});
					};
				};

		    });
	</script>
	<script>
		$(document).ready(function(){
			$("#sopTableList").jqGridFunction({
				//url:'/salesBidding/findBidding',
				dataType:'json',
				postData:{},
				styleUI:'Bootstrap',
				autowidth:true,
				viewrecords:true,
				shrinkToFit:true,
				rowList:[10,20,50,100],
				colNames:['主键','操作','SOP名称','所有者','开始时间','状态','执行人'],
				colModel:[{name:'id',key:true,hidden:true},
							{name:'operat',width:90,formatter:operatFormatter},
				          {name:'name',width:280},
				          {name:'owner',sortable:true},
				          {name:'startTime',sortable:true},
				          {name:'status',sortable:true},
				          {name:'executor',sortable:true}
					     ],
				height:$(document).height()-$("#manage-area-title").height()-130,
				rownumbers: true, // 显示行号
				multiselect:true

			});
			 $(window).bind('resize', function () {  
		            var width = $('.jqGrid_wrapper').width();  
		            $("#sopTableList").setGridWidth(width);
		           // $("#sopTableList").setGridWidth($(window).width()*0.99);　
		        });
			function operatFormatter(cellvalue, options, rowObject){
				var operateHtml = "";
				    operateHtml +='<a title="编辑" href="javascript:layer_shows('+rowObject.id+',1)" class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6df;</i></a>';
				    operateHtml +='<a title="删除" href="javascript:deleSop('+rowObject.id+')"  class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
				return operateHtml;
			};
		});

		//弹出层
		function layer_shows(id,flag){
			if(flag == 1){
				var title = "编辑SOP";
				var url = 'sopManagement-add.html?editId='+id+'&flagId='+'edit';
				var w = "800px";
				var h = "550px";
			}else{
				var title = "招投标表详情";
				var url = 'biddingManagement-detail.html?editId='+id+'&flagId='+'edit';
				var w = "800px";
				var h = "550px";
			}
			layer.open({
				type: 2,
				area: [w , h],
				fix: false, //不固定
				maxmin: true,
				shade:0.2,
				title: title,
				content: url,
				end:function(){
					refresh();
				}
			});
		}

		/*删除*/
		function deleSop(id){
			layer.confirm('确定要删除吗？操作需谨慎',function(){
				$.ajax({
					type:'post',
					dataType:'json',
					async:true,
					url:'/sop/delete',
					data:{
						'id':id
					},
					success:function(data){
						if(data.errorMessage == null){
							layer.msg('已删除!',{icon:1,time:500});
							refresh();
						}else{
							layer.msg(data.errorMessage,{icon:2,time:1000})
						}
					}
				});
			});
		}

//		//高级搜索
//		function biddingSearch(data){
//			$("#sopTableList").setGridParam({
//				url:"/salesBidding/findBidding",
//				datatype: "json",
//				page:1
//			});
//			$("#sopTableList").setPostData(data);
//			$("#sopTableList").trigger("reloadGrid");
//		}
		//刷新
		function refresh(){
			$("#sopTableList").trigger("reloadGrid");
		};


	</script>
</body>
</html>